package com.hongshu.idle.controller.idle;

import com.hongshu.common.core.enums.Result;
import com.hongshu.idle.service.idle.IIdlePaymentPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 闲宝订单
 *
 * @author: hongshu
 */
@RequestMapping("/payment/pay")
@RestController
public class IdlePaymentPayController {

    @Autowired
    private IIdlePaymentPayService paymentPayService;


    /**
     * 创建订单
     *
     * @param paymentOrderId 订单信息
     */
    @GetMapping("createPaymentPay")
    public Result<?> createPaymentPay(String paymentOrderId) {
        return Result.ok(paymentPayService.createPaymentPay(paymentOrderId));
    }

    /**
     * 支付
     */
    @PostMapping("/finish")
    public Result<?> finishPay(String paymentPayId) {
        return Result.ok(paymentPayService.finishPay(paymentPayId));
    }

    /**
     * 取消支付
     */
    @PostMapping("/cancel")
    public Result<?> cancelPay(String paymentPayId) {
        paymentPayService.cancelPay(paymentPayId);
        return Result.ok();
    }

    /**
     * 查询支付结果
     */
    @GetMapping("/status")
    public Result<?> payStatus(String paymentPayId) {
        return Result.ok(paymentPayService.payStatus(paymentPayId));
    }

    /**
     * 更新支付状态
     */
    @PostMapping("/updateOrderStatus")
    public Result<?> updateOrderStatus(String paymentOrderId) {
        paymentPayService.updateOrderStatus(paymentOrderId);
        return Result.ok();
    }

    /**
     * 支付结果回调
     */
    @PostMapping("/notify")
    public String handleAlipayNotify(HttpServletRequest request) {
        return paymentPayService.handleAlipayNotify(request);
    }
}
